package com.cn.demo4.servlet.index;

import com.alibaba.fastjson.JSONObject;
import com.cn.demo4.model.*;
import com.cn.demo4.service.*;
import com.cn.demo4.service.impl.*;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/layout")
public class LayoutServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1.乱码
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");

        //公司信息
        ICompanyService iCompanyService = new CompanyServiceImpl();
        CompanyModel companyModel = iCompanyService.getCompanyModelListForHome();
//        List<CompanyModel> companyModelList = iCompanyService.getCompanyModelListForHome();
//        req.setAttribute("companyModelList",companyModelList);//将数据转发给前台

        //导航信息
        INavService iNavService = new NavServiceImpl();
        List<NavModel> navModelList = iNavService.getNavModelListForHome();
//        req.setAttribute("navModelList",navModelList);//将数据转发给前台
        //产业布局信息
        ILayoutService iLayoutService = new LayoutServiceImpl();
        List<LayoutModel> layoutModelList = iLayoutService.getLayoutModelListForLayout();
//        req.setAttribute("layoutModelList",layoutModelList);

        //咨询信息
        IConsultingService iConsultingService = new ConsultingServiceImpl();
        List<ConsultingModel> consultingModelList = iConsultingService.getConsultingModelListForHome();
//        req.setAttribute("consultingModelList",consultingModelList);

        //留言信息
        IOnlineService iOnlineService = new OnlineServiceImpl();
        List<OnlineModel> onlineModelList = iOnlineService.getOnlineModelListForHome();
//        req.setAttribute("onlineModelList",onlineModelList);

//        req.getRequestDispatcher("/index/jsp/layout.jsp").forward(req,resp);//页面转发，转发数据
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("navModelList",navModelList);
        jsonObject.put("consultingModelList",consultingModelList);
        jsonObject.put("onlineModelList",onlineModelList);
        resp.getWriter().println(jsonObject);
    }
}
